
from metagpt.logs import logger
from pydantic import BaseModel
from fastapi import FastAPI
from starlette.staticfiles import StaticFiles


class ChatReq(BaseModel):
    id: str
    agentPrompt: str


class CommonResult(BaseModel):
    code: int
    message: str
    data: object


app = FastAPI(title='开发智能体', description='基于metagpt的开发智能体')
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.post(path='/api/agent/chat', summary='agent', description='agent chat', tags=['agent'])
async def chat(chat_req: ChatReq) -> CommonResult:
    logger.info(chat_req.json())
    # result: List = await agent.run(chat_req.agentPrompt)
    # chat_resp: ChatResp = ChatResp(id=chat_req.id, data=result)
    # res: CommonResult = CommonResult(code=200, message="查询成功", data=chat_resp)
    res: CommonResult = CommonResult(code=200, message="查询成功", data="hello")
    logger.info(res.json())
    return res


if __name__ == "__main__":
    import uvicorn
    uvicorn.run("main:app", reload=True, workers=4, host="0.0.0.0", port=8084)